#!c:/usr/perl

use strict;
use warnings;
#use encoding 'utf8';

open(INPUT, "input.txt");
open(OUTPUT, ">output.txt");

my @words;
while(my $line = <INPUT>) {
	my @statements = split(/[.?!\s,:;\"\'\(\)\\\/-]/, $line);
	foreach my $wordCandidate (@statements) {
		$wordCandidate = lc $wordCandidate;
		if(length($wordCandidate) > 2 && $wordCandidate =~ m/[a-zęółśążźćń]+/i) {
			push(@words, $wordCandidate);
		}
	}
}

for(my $i = 0 ; $i < scalar(@words) - 2 ; $i += 3) {
	my $word1st = $words[$i];
	my $word2nd = $words[$i + 1];
	my $word3rd = $words[$i + 2];
	print "$word1st $word2nd $word3rd\n";
	print OUTPUT "$word1st $word2nd $word3rd\n";
}

close INPUT;
close OUTPUT;